<template>
  <div class="login-container">
    <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="rules"
      class="login-form"
      auto-complete="on"
      label-position="left"
    >
      <!-- 放置标题图片 @是设置的别名-->
      <div class="title-container">
        <h1 class="title">
          <span>超</span>
          <span>级</span>
          <span>无</span>
          <span>敌</span>
          <span>粉</span>
          <span>噗</span>
          <span>噗</span>
          <span>房</span>
          <span>产</span>
        </h1>
      </div>
      <div class="headportrait">
        <el-avatar :size="80" src="https://img0.baidu.com/it/u=4058009767,2651556095&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800" />
      </div>
      <el-form-item prop="username">

        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          ref="username"
          v-model="loginForm.username"
          placeholder="请输入想注册的用户名"
          name="username"
          type="text"
          tabindex="1"
          auto-complete="on"
        />
      </el-form-item>

      <el-form-item prop="email">
        <i class="el-icon-message" />
        <el-input
          ref="email"
          v-model="loginForm.email"
          placeholder="请输入邮箱"
          name="email"
          tabindex="2"
          auto-complete="on"
          @keyup.enter.native="handleLogin"
        />
      </el-form-item>

      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input
          :key="passwordType"
          ref="password"
          v-model="loginForm.password"
          :type="passwordType"
          placeholder="请输入密码"
          name="password"
          tabindex="3"
          auto-complete="on"
          @keyup.enter.native="handleLogin"
        />
        <span class="show-pwd" @click="showPwd">
          <svg-icon
            :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
          />
        </span>
      </el-form-item>

      <el-button
        class="loginBtn"
        type="primary"
        style="width: 100%; margin-bottom: 30px"
        @click.native.prevent="handleLogin"
        @keyup.native.enter="handleLogin"
      >注册</el-button>

    </el-form>
  </div>
</template>

<script>
import { userRegister } from '@/api/user'
export default {
  data() {
    return {
      passwordType: 'password',
      loginForm: {
        username: '',
        email: '',
        password: ''

      },
      rules: {
        username: [{ required: true, message: '用户名不能为空', trigger: 'blur' },
          { min: 3, max: 20, message: '用户名长度应为3-20之间', trigger: 'blur' }],
        email: [
          { required: true, message: '请输入邮箱长度', trigger: 'blur' },
          { min: 6, max: 20, message: '邮箱长度6-20位', trigger: 'blur' }
        ],
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 20, message: '密码长度6-20位', trigger: 'blur' }]
      },
      state: {
        token: ''
      }
    }
  },
  methods: {

    // z注册
    async handleLogin() {
      console.log(124, this.loginForm)
      this.$refs.loginForm.validate()
      const res = await userRegister(this.loginForm)
      console.log('注册接口数据', res)
      this.$router.push('/login')
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    }
  }
}
</script>

<style lang="scss">
$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  background-image: url("../../assets/common/uhny3qhc0j0uhny3qhc0j0.jpg"); // 设置背景图片
  background-position: center; // 将图片位置设置为充满整个屏幕
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;
    }
    // Chrome浏览器表单自动填充默认样式覆盖方法
    input:-webkit-autofill,
    input:-webkit-autofill:hover,
    input:-webkit-autofill:focus,
    input:-webkit-autofill:active {
      transition-delay: 99999s;
      transition: color 99999s ease-out, background-color 99999s ease-out;
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    color: #454545;
  }
  .el-form-item__error {
    color: #fff;
  }
  .loginBtn {
    background: rgb(229, 133, 166);
    height: 64px;
    line-height: 32px;
    font-size: 24px;
    border-color: rgb(109, 109, 109);
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.el-icon-message{
  color: #e585a6;
  font-size: 18px;
  margin-left: 13px;
}
.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 150px 35px 0;
    margin: 100px auto;
    overflow: hidden;
    background-color: rgba(153, 157, 157, 0.3);
    border-radius: 10px;
  }
.headportrait{
  position: absolute;
  top:30px;
  right: 230px;
}
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      display: flex;
      justify-content: space-between;
      font-size: 38px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
      color:  rgb(229, 133, 166);
    }
  }
.svg-icon{
  color:  rgb(229, 133, 166);
}
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
